/**
 * Created by zwwill on 2017/8/27.
 */

let utilFunc = {
  initFontFamily () {
    let domModule = weex.requireModule('dom')
    domModule.addRule('fontFace', {
      'fontFamily': 'regular',
      'src': "url('/src/assets/fonts/PingFang_Regular.ttf')"
    })
    domModule.addRule('fontFace', {
      'fontFamily': 'medium',
      'src': "url('/src/assets/fonts/PingFang_Medium.ttf')"
    })
    domModule.addRule('fontFace', {
      'fontFamily': 'bold',
      'src': "url('/src/assets/fonts/PingFang_Bold.ttf')"
    })
  },
  getUrlSearch (url, name) {
    const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')
    const r = url.slice(url.indexOf('?') + 1).match(reg)
    if (r != null) {
      try {
        return decodeURIComponent(r[2])
      } catch (_e) {
        return null
      }
    }
    return null
  }
}

export default utilFunc
